package 剑指offer;

import java.util.LinkedList;
import java.util.Queue;

public class _27二叉树的镜像 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) {
            val = x;
        }
    }

    public TreeNode mirrorTree(TreeNode root) {
        if(root == null){
            return null;
        }
        TreeNode mirror_root = null;
        mirror_root = new TreeNode(root.val);
        mirror_root.right = mirror(root.left,mirror_root.right);
        mirror_root.left = mirror(root.right,mirror_root.left);
        return mirror_root;
    }
    public TreeNode mirror(TreeNode root,TreeNode mirror_root){
        if(root == null){
            return mirror_root;
        }else{
            mirror_root = new TreeNode(root.val);
        }
        mirror_root.right = mirror(root.left,mirror_root.right);
        mirror_root.left = mirror(root.right,mirror_root.left);
        return mirror_root;
    }
}
